/**
 * Copyright ©2003~2019年10月6日 szkingdom
 * @author raohj
 * @date 2019年10月6日
 * @file RJVM.java
 * @comment : please input your comment to this file
 * @version : input version
 * @modify:
 * 		1、 2019年10月6日 由 raohj 新建文件
 */
package com.ccnu.demojava.jvm;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map.Entry;
import java.util.Set;

/**
 * @author raohj
 * @date 2019年10月6日
 * @version 
 * @comment to add your comment
 */
public class RJVM {
	static Logger log = LoggerFactory.getLogger(RJVM.class);
	public static void testJMap() {
		// 测试在堆上分配的内存
		RSchoolClass rsc = new RSchoolClass();
		rsc.setRteach(new RTeach("余清平", "1001"));
		for(int i=0; i<100000; i++) {
			RStudent rs = new RStudent();
			rs.setStudentAge("1");
			rs.setStudentName("name" + i);
			rsc.getStudentList().add(rs);
		}
		
		// 沉默一会
		try {
			Thread.currentThread().sleep(100*1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for(int i=0; i<rsc.getStudentList().size(); i++) {
			log.info(rsc.getStudentList().get(i).getStudentName());
		}
		
		Set<Entry<Thread, StackTraceElement[]>> stackSet = Thread.currentThread().getAllStackTraces().entrySet();
		for (Entry<Thread, StackTraceElement[]> entry : stackSet) {
			Thread thread = entry.getKey();
			StackTraceElement[] threadStackTraceEle = entry.getValue();
			if(!thread.equals(Thread.currentThread())) {
				continue;
			}
			
			log.info("======打印Thread[" + thread.getName() + "]的栈情况======");
			for (StackTraceElement stackEle : threadStackTraceEle) {
				log.info("\t" +stackEle + "\n");
			}
		}
	}
}
